import request from '@/utils/request'
import { streamRequest } from '@/api/chat'

import {
  type StreamResponse,
  type TypeQuery,
  type ListResponse,
  PPTListItem,
  ServerData,
} from '@/models/ai-ppt'

export const httpGetPptList = (params: TypeQuery): Promise<ListResponse> => {
  const url: string = params.type === 1 ? '/ppt/show' : '/ppt/recycle-bin/show'
  return request({
    url,
    method: 'get',
    params,
  })
}

export const httpDeletePpt = (id: number, type: number): Promise<any> => {
  const data = { ppt_file_id: id }
  const url: string = type === 1 ? '/ppt/del' : '/ppt/recycle-bin/del'
  return request({
    url,
    method: 'post',
    data,
  })
}

export const getPptOutlineStream = (
  message: string,
): Promise<StreamResponse> => {
  const data = { message }
  return streamRequest(data, '/ppt/chat/sim')
}

export const getPptOutlineStreamFile = (
  file_id?: string,
  content?: string,
): Promise<StreamResponse> => {
  const data = {
    file_id: file_id ? file_id.trim() : '',
    content: content ? content.trim() : '',
  }
  return streamRequest(data, '/ppt/outline-generate/file')
}

export const httpOutlineToPptContent = (
  outline: ServerData[],
  template_id: number,
): Promise<PPTListItem> => {
  const data = { outline, template_id }
  return request({
    url: '/ppt/content-generate',
    method: 'post',
    data,
  })
}

export const httpGetPptData = (id: number): Promise<PPTListItem | null> => {
  const params = { id }
  return request({
    url: '/ppt/content',
    method: 'get',
    params,
  })
}

export const httpSavePptData = (
  id: number,
  name: string,
  image: string,
  content: string,
): Promise<any> => {
  const data = {
    ppt_file_id: id,
    name,
    image,
    content,
  }
  return request({
    url: '/ppt/update',
    method: 'post',
    data,
  })
}

export const httpRestore = (id: number): Promise<any> => {
  const data = { ppt_file_id: id }
  return request({
    url: '/ppt/recycle-bin/restore',
    method: 'post',
    data,
  })
}
// 文生图
export const httpTextToImg = (data: Record<string, string>): any => {
  return request({
    url: `/api/v1/text2img`,
    method: 'post',
    data,
  })
}
